/*
 * Copyright 2010-2011 ESunny.com All right reserved. This software is the
 * confidential and proprietary information of ESunny.com
 * ("Confidential Information"). You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with ESunny.com.
 */
package com.xjt.query.action;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

import com.xjt.cache.RegionCache;
import com.xjt.common.Types.LEADS_SOURCE;
import com.xjt.query.dao.interf.CommonCompanyInfoDao;
import com.xjt.query.dao.pojo.BaseCompanyInfo;
import com.xjt.query.entity.LeadsQueryVo;
import com.xjt.query.entity.RegionModel;

/**
 * leads相关Action
 * 
 * @author Jet Xu 2012-8-3 上午10:05:00
 */
public class QueryLeadsAction extends BaseAction {

    private static final long serialVersionUID = 5838286469449718776L;

    private CommonCompanyInfoDao commonCompanyInfoDao;

    private List<BaseCompanyInfo> dataList;

    private LeadsQueryVo query;

    private Long detailId;

    private Map<String, String> detailMap;

    public String showList() {
        return SUCCESS;
    }

    /**
     * 查询列表
     * 
     * @return
     */
    public String queryList() {
        if (null == query) {
            query = new LeadsQueryVo();
            query.setLeadsSource(LEADS_SOURCE.ALI);
            query.setDateInterval(0);
            query.setPageNo(1);
        }
        int count = commonCompanyInfoDao.countCompanyInfo(query);
        query.doPage(query.getPageNo(), count);
        dataList = commonCompanyInfoDao.queryCompanyInfoPaging(query);
        return SUCCESS;
    }

    /**
     * 显示详情
     * 
     * @return
     */
    public String showDetail() {
        if (null != detailId && null != query) {
            query.setId(detailId);
            BaseCompanyInfo detailInfo = commonCompanyInfoDao.selectCompanyInfoById(query);
            if (null != detailInfo) {
                detailMap = new LinkedHashMap<String, String>();
                detailMap.put("公司名称", detailInfo.getCompanyName());
                detailMap.put("联系人", detailInfo.getContactName());
                detailMap.put("职位", detailInfo.getPosition());
                detailMap.put("公司法人", detailInfo.getLegalPeople());
                detailMap.put("联系电话", detailInfo.getPhone());
                detailMap.put("传真", detailInfo.getFax());
                detailMap.put("手机", detailInfo.getMobile());
                detailMap.put("E-mail", detailInfo.getEmail());
                detailMap.put("邮编", detailInfo.getZipCode());
                detailMap.put("会员号", detailInfo.getMemberNo());
                detailMap.put("注册时间", detailInfo.getRegDate());
                detailMap.put("诚信通年限", detailInfo.getCxtYear());
                detailMap.put("skype", detailInfo.getSkype());
                detailMap.put("qq", detailInfo.getQq());
                detailMap.put("msn", detailInfo.getMsn());
                detailMap.put("年营业额", detailInfo.getAnnualMoney());
                detailMap.put("经营模式", detailInfo.getBuzMode());
                detailMap.put("注册资本", detailInfo.getRegMoney());
                detailMap.put("企业类型", detailInfo.getBuzType());
                detailMap.put("员工人数", detailInfo.getEmployeeNum());
                detailMap.put("成立时间", detailInfo.getFoundDate());
                if (StringUtils.isNotBlank(detailInfo.getProvince())) {
                    try {
                        long provinceid = Long.valueOf(detailInfo.getProvince());
                        RegionModel province = RegionCache.get(provinceid);
                        if (null != province) {
                            detailMap.put("省份", province.getRegionName());
                        }
                    }
                    catch (Exception ex) {
                    }
                }
                if (StringUtils.isNotBlank(detailInfo.getCity())) {
                    try {
                        long cityid = Long.valueOf(detailInfo.getCity());
                        RegionModel city = RegionCache.get(cityid);
                        if (null != city) {
                            detailMap.put("城市", city.getRegionName());
                        }
                    }
                    catch (Exception ex) {
                    }
                }
                detailMap.put("注册地址", detailInfo.getRegAddress());
                detailMap.put("地址", detailInfo.getJyAddress());
                detailMap.put("主营产品", detailInfo.getBuzProduct());
                detailMap.put("主营行业", detailInfo.getBuzIndustry());
                detailMap.put("公司简介", detailInfo.getBuzIntroduction());
            }
            return SUCCESS;
        }
        return ERROR;

    }

    /**
     * @return the query
     */
    public LeadsQueryVo getQuery() {
        return query;
    }

    /**
     * @param query the query to set
     */
    public void setQuery(LeadsQueryVo query) {
        this.query = query;
    }

    /**
     * @return the dataList
     */
    public List<BaseCompanyInfo> getDataList() {
        return dataList;
    }

    /**
     * @param dataList the dataList to set
     */
    public void setDataList(List<BaseCompanyInfo> dataList) {
        this.dataList = dataList;
    }

    /**
     * @return the detailId
     */
    public Long getDetailId() {
        return detailId;
    }

    /**
     * @param detailId the detailId to set
     */
    public void setDetailId(Long detailId) {
        this.detailId = detailId;
    }

    /**
     * @return the detailMap
     */
    public Map<String, String> getDetailMap() {
        return detailMap;
    }

    /**
     * @param detailMap the detailMap to set
     */
    public void setDetailMap(Map<String, String> detailMap) {
        this.detailMap = detailMap;
    }

    /**
     * @param commonCompanyInfoDao the commonCompanyInfoDao to set
     */
    public void setCommonCompanyInfoDao(CommonCompanyInfoDao commonCompanyInfoDao) {
        this.commonCompanyInfoDao = commonCompanyInfoDao;
    }

}
